﻿using System;
using DDDProjectSample.Domain.Repositories;
using DDDProject.Aspects;
using DDDProject.Components;
using DDDProjectSample.Domain;
using DDDProjectSample.Domain.Services;

namespace DDDProjectSample.Application.Controllers
{
    /// <summary>
    /// Controller for Use Case "Members management"
    /// </summary>
    public class MembersController : DomainControllerBase
    {
        private MembersManager _memberManager;

        /// <summary>
        /// Creates a new instance of class MembersController
        /// </summary>
        /// <param name="memberManager">MembersManager domain service</param>
        public MembersController(MembersManager memberManager)
        {
            _memberManager = memberManager;
        }

        /// <summary>
        /// Verifies that the specified user name and password exists in the system
        /// </summary>
        /// <param name="name">The name of the member to validate</param>
        /// <param name="password">The password for the specified member</param>
        /// <returns>True if the member is authenticated, False otherwise</returns>
        public bool ValidateMember(string name, string password)
        {
            // Call the MembersManager to authenticate the user
            Member member = _memberManager.Authenticate(name, password);

            return (member != null);
        }
    }
}
